<template>
  <div class="fin">
    <!-- 头部 -->
    <div class="toubu">
      <header>
        <div class="left" @click="heaclick">
          <span>{{ cityname }}</span>
          <span class="span2"></span>
        </div>
        <van-search v-model="value" placeholder="搜索医生、科室、疾病">
          <template #left-icon>
            <van-icon class-prefix="iconfont" name="extra" />
          </template>
        </van-search>
      </header>
    </div>
    <van-pull-refresh v-model="state.loading" @refresh="onRefresh">
      <!-- 图片 -->
      <div class="pic">
        <div class="top">
          <div class="shang">
            <img class="img1" src="../../assets/img/img1.png" alt="" />
            <div class="tle">快速问医</div>
          </div>
          <div class="shang" @click="hanclick">
            <img class="img1" src="../../assets/img/img2.png" alt="" />
            <div class="tle">名医工作室</div>
          </div>
        </div>
        <div class="bot">
          <div class="xia">
            <img class="img2" src="../../assets/img/img3.png" alt="" />
            <div class="title">
              <span class="span1">患者历荐</span>
              <span class="span2">省时省心省力</span>
            </div>
          </div>
          <div class="xia">
            <img src="../../assets/img/img4.png" class="img2" alt="" />
            <div class="title">
              <span class="span1">专科服务</span>
              <span class="span2">问诊式服务</span>
            </div>
          </div>
          <div class="xia">
            <img src="../../assets/img/img5.png" class="img2" alt="" />
            <div class="title">
              <span class="span1">三甲医院</span>
              <span class="span2">甄选优质医生</span>
            </div>
          </div>
        </div>
      </div>
      <!-- 找医生 -->
      <div class="zys">
        <div class="left">找医生</div>
        <div class="right">
          <span class="span1">全部科室</span>
          <span class="span2"></span>
        </div>
      </div>
      <!-- 科室列表 -->
      <div class="ks">
        <ul>
          <router-link
            v-for="item in list"
            :key="item"
            :to="item.luurl"
            @click="tuiclick(item.title)"
          >
            <span class="iconfont" :class="item.url"></span>
            <p>{{ item.title }}</p>
          </router-link>
        </ul>
      </div>
      <!-- <suspense> -->
      <router-view></router-view>
    </van-pull-refresh>
    <!-- </suspense> -->
  </div>
</template>

<script>
import { ref, provide, reactive } from "vue";
import { Toast } from "vant";
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import { computed, onMounted } from "vue";
export default {
  setup() {
    const router = useRouter();
    const store = useStore();
    const state = reactive({
      loading: false,
    });
    const onRefresh = () => {
      setTimeout(() => {
        Toast("刷新成功");
        state.loading = false;
      }, 500);
    };
    const value = ref("");
    const hanclick = () => {
      router.push("/studio");
    };
    //计算属性拿取vuex里面的数据
    const count = computed(() => store.state.recommend);
    const cityname = computed(() => store.state.cityname);
    //点击事件请求数据
    const tuiclick = (a) => {
      setRecommend(a);
    };
    // const onload = () => {
    //   console.log(1);
    //   router.push("/home/finddoctor/tuijian");
    // };
    //初始化渲染推荐数据
    onMounted(() => {
      setRecommend();
    });
    //调用active函数
    const setRecommend = (a) => store.dispatch("getRecommend", a);
    //依赖注入
    provide("count", count);

    const heaclick = () => {
      router.push("/aduss");
    };

    const list = ref([
      {
        url: "icon-tuijian",
        title: "推荐",
        luurl: "/home/finddoctor/tuijian",
      },
      {
        url: "icon-fuchanke-01",
        title: "妇产科",
        luurl: "/home/finddoctor/fuchanke",
      },
      {
        url: "icon-erke---",
        title: "儿科",
        luurl: "/home/finddoctor/erke",
      },
      {
        url: "icon-icon23201",
        title: "内科",
        luurl: "/home/finddoctor/neke",
      },
      {
        url: "icon-waike",
        title: "外科",
        luurl: "/home/finddoctor/waike",
      },
      {
        url: "icon-pifu_icon-copy",
        title: "皮肤科",
        luurl: "/home/finddoctor/pifuke",
      },
    ]);
    return {
      value,
      list,
      state,
      onRefresh,
      router,
      hanclick,
      tuiclick,
      heaclick,
      cityname,
      setRecommend,
      count,
      onload,
    };
  },
};
</script>
<style lang="less">
.fin {
  position: relative;
  background: white;
  @font-face {
    font-family: "iconfont";
    src: url("../../assets/font/iconfont.ttf") format("truetype");
  }
  .iconfont {
    font-family: "iconfont" !important;
    font-size: 18px;
    font-style: normal;
    font-weight: 600;
    opacity: 0.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  .iconfont-extra::before {
    content: "\e62d";
  }
  .toubu {
    width: 100%;
    background: white;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1000;
  }
  header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .left {
      margin-left: 18px;
      // width: 97px;
      height: 21px;
      font-size: 20px;
      font-weight: 445;
      color: #000000;
      line-height: 18px;
      display: flex;
      align-items: center;
      .span2 {
        margin-left: 2px;
        display: block;
        height: 5px;
        border: 3px #000000 solid;
        border-left-color: rgba(222, 222, 222, 0);
        border-right-color: rgba(222, 222, 222, 0);
        border-bottom-color: rgba(222, 222, 222, 0);
      }
    }
    .van-search__content {
      width: 223px;
      height: 35px;
      background: #f4f5f9;
      border-radius: 17px;
      .van-field__control {
        font-size: 14px;
        font-weight: 500;
        color: #999999;
      }
    }
  }
  .pic {
    margin-top: 55px;
    padding: 0 14px;
    width: 100%;
    .top {
      margin-bottom: 10px;
      display: flex;
      justify-content: space-between;
      .shang {
        position: relative;
        .img1 {
          width: 168px;
        }
        .tle {
          position: absolute;
          top: 20px;
          left: 17px;
          font-size: 18px;
          font-weight: 500;
        }
      }
    }
    .bot {
      display: flex;
      justify-content: space-between;
      .xia {
        position: relative;
        .img2 {
          width: 108px;
        }
        .title {
          span {
            display: block;
          }
          .span2 {
            font-size: 10px;
            margin-top: 5px;
            font-weight: 500;
            color: #5e6370;
          }
          position: absolute;
          top: 15px;
          left: 17px;
          font-size: 15px;
          font-weight: 500;
        }
      }
    }
  }
  .zys {
    width: 100%;
    margin: 30px 0 15px 0;
    padding: 0 14px;
    display: flex;
    justify-content: space-between;
    .left {
      height: 21px;
      font-size: 22px;
      font-weight: 445;
      color: #333333;
      line-height: 18px;
    }
    .right {
      display: flex;
      justify-content: space-between;
      .span1 {
        display: inline-block;
        // width: 52px;
        height: 13px;
        font-size: 13px;
        font-weight: 500;
        color: #999999;
        line-height: 18px;
      }
      .span2 {
        display: inline-block;
        margin-left: 6px;
        align-self: center;
        width: 7px;
        height: 7px;
        border-right: 1px solid #999999;
        border-top: 1px solid #999999;
        position: relative;
        transform: rotate(45deg);
      }
    }
  }
  .ks {
    width: 100%;
    ul {
      display: flex;
      width: 100%;
      a {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-evenly;
        align-items: center;
        // padding-bottom: 20px;
        border-bottom: 1px #e9dcdc solid;
        .iconfont {
          font-size: 26px;
          font-weight: 400;
        }
        p {
          // width: 40px;
          height: 12px;
          font-size: 13px;
          font-weight: 450;
          color: #5e6370;
          line-height: 18px;
          text-align: center;
          margin-bottom: 17px;
        }
      }
      .router-link-active {
        p,
        .iconfont {
          color: #0083ff;
        }
        &::after {
          content: "";
          width: 26px;
          height: 2px;
          background: #0083ff;
          // background: @theme-color;
          // position: absolute;
          // bottom: 4px;
          // left: 50%;
          // transform: translateX(-50%);
          // border-radius: 2px;
        }
      }
    }
  }
}
</style>
